package demo1;

import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ASUS
 * Date: 2024-03-09
 * Time: 9:21
 */
public class Test2 {
    public static void main(String[] args) {
        String s = new String();
        if (isValid(s)){
            return ;
        }

    }


    public static boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();

        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == '(' || ch == '[' || ch == '{'){
                stack.push(ch);
            }else {
                if (stack.empty()){
                    return false;
                }else {
                    char tmp = stack.peek();
                    if (ch == ')' && tmp=='('||ch == ']' && tmp=='['||ch == '}' && tmp=='{'){
                        stack.pop();
                    }else {
                        return false;
                    }
                }
            }
        }
        return true;
    }
}
